package hesso.smartdraw.ch.guielements;

import java.util.ArrayList;

import org.anddev.andengine.entity.primitive.Line;
import org.anddev.andengine.entity.scene.Scene;

public class Grid {
	
	private int screenWidth;
	private int screenHeight;
	
	private int lineCount;
	private int displacement;
	
	private Scene scene;
	
	private ArrayList<Line> lines = new ArrayList<Line>();

	public Grid(Scene scene, int screenWidth, int screenHeight, int lineCount) {
		
		this.scene = scene;
		
		this.screenWidth = screenWidth;
		this.screenHeight = screenHeight;
		this.lineCount = lineCount;
		
		this.displacement = screenWidth / lineCount;
		
		
	}
	
	public void drawGrid() {
		
		for(int i = 0; i <= screenWidth*10; i += displacement) {
			
			Line tempLineV = new Line( 0 - screenHeight*10 + i, 0 - screenHeight*10, 0 - screenHeight*10 +  i, 0 + screenHeight*10, 1);
			tempLineV.setColor(0.3f, 0.3f, 0.3f);
			Line tempLineH = new Line(0 - screenHeight*10, 0 - screenHeight*10 + i, 0 + screenHeight*10, 0 - screenHeight*10 +  i, 1);
			tempLineH.setColor(0.3f, 0.3f, 0.3f);
			lines.add(tempLineV);
			lines.add(tempLineH);
			scene.attachChild(tempLineV);
			scene.attachChild(tempLineH);
		}
	}
	
	public void removeGrid() {
		
		for(Line line : lines) {
			
			scene.detachChild(line);
		}
	}
}
